/**
 * @author awooldri
 */


YAHOO.namespace("example.container");
YAHOO.namespace('alw.ibrpg.globals.container');

var yaig = YAHOO.alw.ibrpg.globals;
var yud = YAHOO.util.Dom;
var yue = YAHOO.util.Event;

function init() {
	var panelWidth = 420;
	//get width of viewport
	var vpWidth = YAHOO.util.Dom.getViewportWidth();
	console.log(vpWidth);
	stX = vpWidth - panelWidth - 100;
	actX = vpWidth - 200;
	
	// Instantiate a Panel from script
	yaig.container.panel2 = new YAHOO.widget.Panel("panel2", { 
		width:"420px", 
		visible:false, 
		draggable:false, 
		close:false,
		xy: [stX,0],
		effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}, 
	            {effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.5}] 
	});
	yaig.container.panel2.setHeader("Itty Bitty RPG");
	yaig.container.panel2.setBody("<div id='tabcontainer'></div>");
	yaig.container.panel2.setFooter("<button value='IBRPG' id='hideibrpg'>CLOSE</button>");
	yaig.container.panel2.render("container");

	//YAHOO.example.container.panel2.show();	
	
	var actuator = document.createElement('div');
	
	actuator.innerHTML="<button id='showibrpg'>ITTY BITTY RPG</button>";
	document.body.appendChild(actuator);
	YAHOO.util.Dom.setXY(actuator,[actX,0]);
	
	
	
	
	
	YAHOO.util.Event.addListener("showibrpg", "click", yaig.container.panel2.show, yaig.container.panel2, true);
	YAHOO.util.Event.addListener("hideibrpg", "click", yaig.container.panel2.hide, yaig.container.panel2, true);

	
	
	
	
		
	(function() {
		yaig.tabView = new YAHOO.widget.TabView({orientation:"bottom"});
		yaig.tabView.addTab( new YAHOO.widget.Tab({
			label: 'lorem',
			content: '<p>Welcome to Itty Bitty RPG!</p><p>Here you will be able to play a simple RPG and have fun in the process.<a href="" id="clicktocont">Click here to continue</a></p>',
			active: true
		}));
/**
		tabView.addTab( new YAHOO.widget.Tab({
			label: 'ipsum',
			content: '<ul><li><a href="#">Lorem ipsum dolor sit amet.</a></li><li><a href="#">Lorem ipsum dolor sit amet.</a></li><li><a href="#">Lorem ipsum dolor sit amet.</a></li><li><a href="#">Lorem ipsum dolor sit amet.</a></li></ul>'

		}));

		tabView.addTab( new YAHOO.widget.Tab({
			label: 'dolor',
			content: '<form action="#"><fieldset><legend>Lorem Ipsum</legend><label for="foo"> <input id="foo" name="foo"></label><input type="submit" value="submit"></fieldset></form>'
		}));
		YAHOO.log("The example has finished loading; as you interact with it, you'll see log messages appearing here.", "info", "example");
**/

		yaig.tabView.appendTo('tabcontainer');
})();
			
function newTab(e){
	yaig.tabView.addTab( new YAHOO.widget.Tab({ label: 'instructions', content: 'instructions' }) ); 
	yaig.tabView.set('activeIndex', 1);
	yue.stopEvent(e)
	}
	yue.on('clicktocont',"click",newTab)		
	//prefs
			
var rpgprefs = prefs.load();
if(!!rpgprefs.visits){
	rpgprefs.visits++;
} else {
	prefs.data.visits = 1;
}
prefs.save();
console.log("prefs data visits: "+prefs.data.visits)			
	
	
			
			
		}

		YAHOO.util.Event.addListener(window, "load", init);